/**
 * 功能描述
 */

define(function (require, exports, module) {
	
	var store =require("store");
	var activeUser = store.get("user");
    module.exports = {
    		form: {
    	    	searchContact:function(widget,memberCertificates,pkReturnCredentials,dat){
    	    		var d = dat;
    				widget.service.queryTravelcontract({
    					memberCertificates:memberCertificates,
    					pkReturnCredentials : pkReturnCredentials,
    	           		fetchProperties:
    	           			"travelContract.memberCertificates,travelContract.pkTravelContract,travelContract.contactNo,travelContract.status.*,travelContract.productRule.product.pkProduct,travelContract.version," +
               				"travelContract.productRule.product.name,travelContract.productType.pkProductType,travelContract.productType.name," +
               				"travelContract.number,travelContract.price,balance,travelContract.signUpDate,travelContract.member.personalInfo.pkPersonalInfo," +
               				"travelContract.member.personalInfo.name,travelContract.member.personalInfo.idNumber,travelContract.member.personalInfo.phone,travelContract.member.personalInfo.mobilePhone," +
               				"welfareccList.pkWelfarecc,welfareccList.cardNo,welfareccList.count,welfareccList.returnCertificateTotal,welfareccList.consumptionTotal,welfareccList.cashTotal,welfareccList.balance"
    			},function(data){
    					var form = widget.get("form");
    					form.setValue("memberCertificates",data.travelContract.memberCertificates);
    					form.setValue("contactNo",data.travelContract.contactNo);
    					form.setValue("status.value",data.travelContract.status.value);
    					form.setValue("product.name",data.travelContract.productRule.product.name);
    					form.setValue("productType.name",data.travelContract.productType.name);
    					form.setValue("number",data.travelContract.number);
    					form.setValue("totalPrice",data.travelContract.price);
    					form.setValue("signUpDate",data.travelContract.signUpDate);
    					form.setValue("balance",data.balance);
    					form.setValue("name",data.travelContract.member.personalInfo.name);
    					form.setValue("idNumber",data.travelContract.member.personalInfo.idNumber);
    					form.setValue("mobilePhone",data.travelContract.member.personalInfo.mobilePhone==null?" ":data.travelContract.member.personalInfo.mobilePhone);
    					form.setValue("defaultRatio",d.defaultRatio==null?0.00:(d.defaultRatio).toFixed(2));
    					form.setValue("flatCost",d.flatCost==null?0.00:(d.flatCost).toFixed(2));
    					form.setValue("operateDate",d.operateDate);
    					form.setValue("price",d.price==null?0.00:(d.price).toFixed(2));
    					form.setValue("operate",activeUser.name); //d.operator.pkUser
    					form.setValue("cause",d.cause);
    					
    					var coupongrid = widget.get("couponGrid");
    					coupongrid.setData(data.welfareccList);
    					widget.hide([".J-grid"]).show([".J-form",".J-couponGrid"]);
    					widget.get("subnav").hide(["search","status"]).show(["back"]);	
    					var pkReturnCredentials = d.pkReturnCredentials;
    					if(pkReturnCredentials != null){
    						form.setDisabled(true);
    						var coupongrid = widget.get("couponGrid");
    						widget.show([".J-form",".J-couponGrid",".J-approvalUI"]).hide([".J-grid"]);
        					widget.get("subnav").hide(["search","status"]).show(["back"]);	
        					//加载审批流
        					var approvalUI  = widget.get("approvalUI");
							approvalUI.set("param",{
								modelId:pkReturnCredentials,
								serviceType:"ReturnCredentials",
								hideButton:true
							});
							approvalUI.get("appgrid").refresh();
        					
    						
    					}
    	 			})
    			}
    	    },
    		
    grid: {
    	searchContact:function(widget,memberCertificates,pkReturnCredentials,dat){
    		var d = dat;
			widget.service.queryTravelcontract({
				memberCertificates:memberCertificates,
				pkReturnCredentials : pkReturnCredentials,
           		fetchProperties:
       				"welfareccList.pkWelfarecc,welfareccList.cardNo,welfareccList.count,welfareccList.returnCertificateTotal,welfareccList.consumptionTotal,welfareccList.cashTotal,welfareccList.balance," 
       				
		},function(data){				
				var coupongrid = widget.get("couponGrid");
				coupongrid.setData(data.welfareccList);
				widget.hide([".J-grid"]).show([".J-form",".J-couponGrid"]);
				widget.get("subnav").hide(["search","status"]).show(["back"]);	
 			})
		}
    }
    		
  };
});
